{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 网站访问人数为100的概率【困难】"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有一个小网站，平均每天访问人数为8个左右，求某天访问人数为100人的概率。\n",
    "\n",
    "注：本题非Python编码题，主要考察概率统计知识。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#==============================答题区==============================#\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#==============================答题区==============================#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#==============================提示区==============================#\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#  提示：Possion分布\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#==============================提示区==============================#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.322159572232768e-72\n"
     ]
    }
   ],
   "source": [
    "#==============================答案区==============================#\n",
    "# 解题思路：Possoin分布\n",
    "# 由于存在大量的互联网用户，每个用户都有极小的概率去访问这个网站\n",
    "# 所以这个网站每天访问的人数服从泊松分布，且参数lambda为8\n",
    "\n",
    "from scipy.stats import poisson\n",
    "\n",
    "#访问人数为100人的概率\n",
    "print(poisson.pmf(100,8))\n",
    "\n",
    "#==============================答案区==============================#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoA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p7U9FOsxDUTY9orVwRE79KhUD45G031isjVTUJuvS3CPryOYm2QbRj8hDUTadUNE8YOYk+VMN5NUt9wVd96wLDBGdvU6K3WbsEF8+2728I42vUz+Y6lGUTadUNA+YcVpvq//Uf1s9YLhOON+qsTNO7PUPyYxPUD/FD7K3eFuTkd2dxj+Qv/4oyqYbVHS/cVc4jV46rca5orPbLGh6RU1yYvq7ylzxTH4HX4p29iicLxpU20Vqre7xZ2GZyGhLxPudemstq/m/KJtOmGnv65bRYsv+lTi/RA9lXo1+9tXAJpwl+iFf4GzdezXQNU6Vv9jtTbonZMYnid9YrBcnZbe4OGtFTZS9sxdo3eJ++wDZdEKr9Xrr2IzBc6Ilv0v0TBYrf15QUlJSUlJSUrLP/AfmKYpZsKoHfwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$7.3222 \\cdot 10^{-72}$$"
      ],
      "text/plain": [
       "7.3222e-72"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#==============================答案区==============================#\n",
    "# 解题思路：Possoin分布\n",
    "# 由于存在大量的互联网用户，每个用户都有极小的概率去访问这个网站\n",
    "# 所以这个网站每天访问的人数服从泊松分布，且参数lambda为8\n",
    "\n",
    "import sympy \n",
    "from sympy import stats,symbols\n",
    "from sympy.stats import Poisson\n",
    "sympy.init_printing()\n",
    "\n",
    "lam = symbols('lambda',positive = True)\n",
    "x = symbols(\"x\")\n",
    "\n",
    "X = stats.Poisson('X',lam)\n",
    "\n",
    "stats.density(X)(100).subs({lam:8}).n(5)\n",
    "\n",
    "#==============================答案区==============================#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](../Python与算法之美.jpg)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
